package com.wjm.demo.test2;


import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class UploadPicClient {
    public static void main(String[] args) throws Exception {

//        String file="H:\\Android书\\图片\\ezgif.com-video-to-gif.gif";
//        String file = "H:\\迅雷下载\\开发\\genymotion-2.8.1-vbox.exe";//151
        String file = "H:\\迅雷下载\\开发\\AS\\android-studio-ide-173.4819257-windows32.zip";//854//25584

        long start = System.currentTimeMillis();

        Socket s = new Socket("192.168.0.101", 10001);
//        FileInputStream fis = new FileInputStream("d:\\微信截图_20180707211416.png");
        FileInputStream fis = new FileInputStream(file);
        OutputStream out = s.getOutputStream();
        int len;
        byte[] buf = new byte[1024];
        while ((len = fis.read(buf)) != -1) {
            out.write(buf, 0, len);
        }
        s.shutdownOutput();//结束标记

        InputStream is = s.getInputStream();
        byte[] bytes = new byte[1024];
        int bytesLen = is.read(bytes);
        String str = new String(bytes, 0, bytesLen);
        if ("上传成功".equals(str)) {
            long end = System.currentTimeMillis();
            long timeConsuming = end - start;
            System.out.println("上传耗时" + timeConsuming);
//            System.out.println("上传耗时" + formatSecond(timeConsuming));
        }
        System.out.println(str);
        fis.close();
        s.close();
    }

    public static String getTime(long time) {
        String temp = time / (24 * 60 * 60) + "天";
        temp += time % (24 * 60 * 60) / (60 * 60) + "小时";
        temp += time % (24 * 60 * 60) % (60 * 60) / 60 + "分钟";
        temp += time % (24 * 60 * 60) % (60 * 60) % 60 + "秒";
        return temp;
    }


    public static String formatSecond(long s) {
        String html = "0秒";
        if (s > 0) {
            String format;
            Object[] array;
            Integer hours = (int) (s / (60 * 60));
            Integer minutes = (int) (s / 60 - hours * 60);
            Integer seconds = (int) (s - minutes * 60 - hours * 60 * 60);
            if (hours > 0) {
                format = "%1$,d时%2$,d分%3$,d秒";
                array = new Object[]{hours, minutes, seconds};
            } else if (minutes > 0) {
                format = "%1$,d分%2$,d秒";
                array = new Object[]{minutes, seconds};
            } else {
                format = "%1$,d秒";
                array = new Object[]{seconds};
            }
            html = String.format(format, array);
        }

        return html;
    }


}
